﻿<!doctype html>
 <html >
 <head>
   <meta charset="UTF-8">
   <link rel="stylesheet" href="/css/common.css">
   <link rel="stylesheet" href="/css/main.css">
   <script type="text/javascript" src="/js/jquery.min.js"></script>
   <script type="text/javascript" src="/js/colResizable-1.3.min.js"></script>
   <script type="text/javascript" src="/js/common.js"></script>
</head>

<body>
  <div id="forms" class="mt10">
        <div class="box">
          <div class="box_border">
            <div class="box_top"><b class="pl15">修改密码</b></div>
            <div class="box_center">
              <form action="list.ftl" class="jqtransform">
                  <input type="hidden" id="username" name="username" value="${user.username}">
               <table class="form_table pt15 pb15" width="100%" border="0" cellpadding="0" cellspacing="0">
                 <tr>
                  <td class="td_right">原密码：</td>
                  <td class=""> 
                    <input type="password" id="oldPassword" name="oldPassword" class="input-text lh30" size="40">
                  </td>
				  </tr>
				  <tr>
                  <td class="td_right">新密码：</td><td><input type="password" id="newPassword" name="newPassword" class="input-text lh30" size="40"></td>
                </tr>
					   <tr>
						  <td class="td_right">确认密码：</td>
						  <td class=""> 
							<input type="password" id="pwd2" name="pwd2" class="input-text lh30" size="40">
						  </td>
					  </tr>
			
                   <td class="td_right">&nbsp;</td>
                   <td class="">
                     <input type="button" name="button" class="btn btn82 btn_save2" onclick="subMit()" value="保存">
                    <input type="button" name="button" class="btn btn82 btn_res" onclick="location.href='javascript:history.go(-1)'" value="返回"> 
                   </td>
                 </tr>
               </table>
               </form>
            </div>
          </div>
        </div>
     </div>
   </div> 
</body>
<script>
    function subMit() {
        var username = $("#username").val();
        var oldPassword=$("#oldPassword").val();
        var newPassword=$("#newPassword").val();
        var pwd2 = $("#pwd2").val();
        if(oldPassword==null||oldPassword.trim().length===0){
            alert("旧密码不能为空");
            return;
        }
        if(newPassword==null||newPassword.trim().length==0){
            alert("新密码不能为空");
            return;
        }
        if(pwd2==null||pwd2.trim().length==0){
            alert("确认密码不能为空");
            return;
        }
        if(newPassword.trim().length<6){
            alert("密码长度不能低于6为");
            return;
        }
        if(newPassword!=pwd2){
            alert("两次密码不一致")
            return;
        }
        $.post(
            "${req.contextPath}/updated/password",
            {"username":username,"oldPassword":oldPassword,"newPassword":newPassword},
            function (result) {
                if(result.code==0){
                    alert("修改密码成功，请返回页面重新登录");
                    top.location.href="${req.contextPath}/user/logout";
                }else{
                    alert(result.msg);
                }
            }

        )
    }
</script>
</html>